var {
  swipeUtils,
  ocrUtils,
  timeUtils,
  randomUtils,
  textUtils,
  logUtils,
} = require("../../utils/index");
var Action = require("../../base/Action");
var aWatchVideo = new Action("看视频", {});
aWatchVideo.randomNextVideo = function () {
  var contents = [
    //prettier-ignore
    "点击进入",
    "直播间",
    "点击重播",
    "轻触屏幕",
    "领奖励",
  ];
  if (textUtils.existsOneTextStartsWith(contents)) {
    logUtils.info(1, "将看下一个视频");
    swipeUtils.swipeVideo();
    return;
  }
  if (ocrUtils.captureExistsOneText(contents)) {
    logUtils.info(2, "将看下一个视频");
    swipeUtils.swipeVideo();
    return;
  }
  if (randomUtils.possible(70, 100)) {
    logUtils.info(3, "将看下一个视频");
    swipeUtils.swipeVideo();
    return;
  }
};
aWatchVideo.exec = function () {
  var startTime = Date.now();
  var count = 0;
  var span = 130 * 60 + randomUtils.getRandom(5, 15);
  while (true) {
    var interval = randomUtils.getRandom(10, 30);
    logUtils.info("将看：", interval, "s");
    sleep(interval * 1000);
    count++;
    var hasExec = timeUtils.hasExec(startTime);
    if (count % 5 == 0) {
      logUtils.info("已经看了-" + hasExec + "/" + span + "-s");
    }
    if (hasExec >= span) {
      logUtils.info("时间已到，将结束看视频");
      break;
    }
    this.randomNextVideo();
  }
};

module.exports = aWatchVideo;
